﻿@using Abp.Json
@using Abp.Extensions
@using Partner.Surround.Core.DataDictionaries.DataDictionaryItems.Dto
@model DataDictionaryItemEditDto
@section styles{
    <style type="text/css">
        body {
            background: #fafafa !important;
        }
    </style>
}
<div class="layui-fluid">
    <form class="layui-form" lay-filter="layui-form-dataDictionaryItem" style="padding: 15px 0 0 0;">
        <input type="hidden" name="id" />
        <input type="hidden" name="dataDictionaryId" />
        <div class="layui-form-item">
            <label class="layui-form-label">业务代码</label>
            <div class="layui-input-inline">
                <input type="text" name="code" lay-verify="required" placeholder="请输入业务代码" autocomplete="off" class="layui-input @(Model.Id >0 ? "layui-disabled" : "")" @(Model.Id >0 ? "readonly" : "")>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-inline">
                <input type="text" name="name" placeholder="请输入名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-hide" lay-submit lay-filter="LAY-dataDictionaryItem-front-submit" id="LAY-dataDictionaryItem-front-submit">立即提交</button>
            </div>
        </div>
    </form>
</div>

@section scripts{
    <script type="text/javascript">
        layui.config({
            base: '/lib/layui-extend-modules/' //静态资源所在路径
        }).use(['jquery', 'form', 'layer', 'table'], function () {
            var $ = layui.$,
                form = layui.form;

                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.iframeAuto(index);

                //初始化表单
                form.val("layui-form-dataDictionaryItem",@Html.Raw(JsonExtensions.ToJsonString(Model,true,false)));
                form.render();

                //触发表单提交
                layui.submitForm = function(){
                    $("#LAY-dataDictionaryItem-front-submit").click();
                }

                form.on('submit(LAY-dataDictionaryItem-front-submit)', function (data) {
                    var field = {
                        dataDictionaryItem: data.field, //获取提交的字段
                    };

                    var waitIndex = parent.layer.load(2);
                    abp.ajax({
                        url: "@Url.Action("CreateOrUpdateDataDictionaryItem", "DataDictionary", new { area="Core" })",
                        data: JSON.stringify(field),
                        abpHandleError: false
                    }).done(function (data) {
                        if (data.code == 200) {
                            data.index = index;
                            parent.layui.dataDictionaryItemCallback(data);
                        }
                    }).fail(function (jqXHR) {
                        parent.layer.msg(jqXHR.message, { icon: 5 });
                    }).always(function () {
                        parent.layer.close(waitIndex);
                    });

                    return false;
               });
        });
    </script>
}
